/**
 * ReportGear(2011)
 */
package com.reportgear.designer.action.core;

import java.awt.event.KeyEvent;

import javax.swing.Action;
import javax.swing.KeyStroke;

import com.reportgear.report.model.cell.style.Style;

/**
 * Action实用类
 * 
 * @version 1.0 2011-4-26
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class ActionUtils {
	/**
	 * 创建提示文本
	 * 
	 * @param action
	 *            事件
	 * @return 提示文本
	 */
	public static String createButtonToolTipText(Action action) {
		StringBuilder sb = new StringBuilder();
		String str = (String) action.getValue("Name");

		if (str.lastIndexOf("(") > -1) {
			sb.append(str.substring(0, str.lastIndexOf("(")));
		} else {
			sb.append(str);
		}

		KeyStroke strokey = (KeyStroke) action.getValue("AcceleratorKey");

		if (strokey != null) {
			sb.append(" (");
			sb.append(KeyEvent.getKeyModifiersText(strokey.getModifiers()));
			sb.append("+");
			sb.append(KeyEvent.getKeyText(strokey.getKeyCode()));
			sb.append(")");
		}

		return sb.toString();
	}

//	public static boolean executeAction(StyleActionInterface paramStyleActionInterface, ReportPane paramReportPane) {
//		ElementCase localElementCase;
//		Object localObject1;
//		Style localStyle1 = null;
//		GridSelection localGridSelection = paramReportPane.getGridSelection();
//		int i = localGridSelection.getType();
//		if (i == 1) {
//			localElementCase = paramReportPane.getEditingElementCase();
//			localObject1 = localElementCase.getFloatElement(localGridSelection.getLastFloatName());
//			localStyle1 = ((FloatElement) localObject1).getStyle();
//			((FloatElement) localObject1).setStyle(paramStyleActionInterface.executeStyle(localStyle1, localStyle1));
//		} else {
//			localElementCase = paramReportPane.getEditingElementCase();
//			localObject1 = localGridSelection.getEditRectangle();
//			Object localObject2 = localElementCase.getCellElement(((Rectangle) localObject1).x,
//					((Rectangle) localObject1).y);
//			if (localObject2 == null) {
//				localObject2 = new DefaultCellElement(((Rectangle) localObject1).x, ((Rectangle) localObject1).y);
//				localElementCase.addCellElement((CellElement) localObject2);
//			}
//			localStyle1 = ((CellElement) localObject2).getStyle();
//			int j = localGridSelection.getCellRectangleCount();
//			for (int k = 0; k < j; ++k) {
//				Rectangle localRectangle = localGridSelection.getCellRectangle(k);
//				for (int l = localRectangle.height - 1; l >= 0; --l)
//					for (int i1 = localRectangle.width - 1; i1 >= 0; --i1) {
//						int i2 = i1 + localRectangle.x;
//						int i3 = l + localRectangle.y;
//						localObject2 = localElementCase.getCellElement(i2, i3);
//						if (localObject2 == null) {
//							localObject2 = new DefaultCellElement(i2, i3);
//							localElementCase.addCellElement((CellElement) localObject2);
//						} else {
//							if (((CellElement) localObject2).getColumn() != i2)
//								continue;
//							if (((CellElement) localObject2).getRow() != i3)
//								continue;
//						}
//						Style localStyle2 = ((CellElement) localObject2).getStyle();
//						((CellElement) localObject2).setStyle(paramStyleActionInterface.executeStyle(localStyle2,
//								localStyle1));
//					}
//			}
//		}
//		return true;
//	}
//
//	public static Style getCurrentStyle(ReportPane paramReportPane) {
//		ElementCase localElementCase = paramReportPane.getEditingElementCase();
//		GridSelection localGridSelection = paramReportPane.getGridSelection();
//		int i = localGridSelection.getType();
//		if (i == 1) {
//			localObject = localElementCase.getFloatElement(localGridSelection.getLastFloatName());
//			return ((FloatElement) localObject).getStyle();
//		}
//		Object localObject = localGridSelection.getEditRectangle();
//		CellElement localCellElement = localElementCase.getCellElement(((Rectangle) localObject).x,
//				((Rectangle) localObject).y);
//		if (localCellElement == null)
//			return Style.DEFAULT_STYLE;
//		return ((Style) localCellElement.getStyle());
//	}
//
//	public static void checkContainReportEnabled(ReportAction paramReportAction) {
//		paramReportAction.setEnabled(true);
//		ReportPane localReportPane = paramReportAction.getEditingReportPane();
//		if (localReportPane != null)
//			return;
//		paramReportAction.setEnabled(false);
//	}
}
